
class Animal:

    def __init__(self,name,age,sex):
        self.name = name
        self.age  = age
        self.sex  = sex
        print("-----父类的构造方法")

    def eat(self):
        print("%s is eating...."% self.name)

class Person(Animal): # 继承了Animal的属性，方法

    a_type = "哺乳高级动物"

    def __init__(self,name,age,sex,hobbie):
        # Animal.__init__(self,name,age,sex)
        # super(Person,self).__init__(name,age,sex) # super 上传子类和实例  效果同上
        super().__init__(name,age,sex) # 跟上一句效果一样
        self.hobbie = hobbie
        print("-----子类的构造方法")

    def talk(self):
        print("perdon %s is talking..."% self.name)

    def eat(self): # 重写覆盖 父类方法
        super().eat() # 函数里效果一样，执行父类的方法
        print("%s在优雅的吃饭..."% self.name)

class Dog(Animal):

    def chase_rabbit(self):
        print("狗%s在追兔子..."% self.name)



p = Person("Alex",22,"M","女人")
p.eat()
p.talk()

print(p.name,p.sex,p.hobbie)

# d = Dog("Mjj",3,"Female")
# d.eat()
# d.chase_rabbit()

